﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ESAM_Assignment_3
{
    public partial class DeleteComment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int CommentID;

                if (Int32.TryParse(Encryption.DecryptQueryString(HttpUtility.UrlDecode(Request.QueryString["CommentID"])), out CommentID) && CommentClass.GetComment(CommentID).Username == User.Identity.Name)
                {
                    lblCommentID.Text = CommentID.ToString();

                    bool status = CommentClass.DeleteComment(CommentID);

                    if (status)
                    {
                        lblStatus.ForeColor = System.Drawing.Color.Blue;
                        lblStatus.Text = "Success. Comment has been deleted.";

                    }
                    else
                    {
                        lblStatus.ForeColor = System.Drawing.Color.Red;
                        lblStatus.Text = "We encountered an error. Your comment was not deleted.";
                    }
                }
            }
        }
    }
}
